#!/bin/bash -l

echo 
echo "IntelMPI"
echo "========"

export DEFAULT_DATAFILE="data/instance038c1.txt"
export NBR_NODES=4

export PROGRAM_NAME=bin/mpii-samebatch-multiproduct-binpacking
export MPIRUN_CMD="mpirun"

if [ `hostname` == "pc-gi-90" ]
then
    echo pc-gi-90
else
    echo mesocluster

    echo module rm ompi
    module rm ompi
fi

# script pouvant etre executer depuis le repertoire parent par 
# la commande script/runmpi
# ou depuis le repertoire src (travail avec emacs)
if [ ! -d "bin" ]; then
    echo moving to parent directory
    cd ..
fi
pwd

export CMD_LINE_PARAMS$1 $2 $3 $4 $5 $6 $7 $8 $9
if [ $# = 0 ]; then
    export CMD_LINE_PARAMS="-bbp ${DEFAULT_DATAFILE}"
fi 

# Interval of the search tree to dispatch the work to the slaves
# If the task are too small, the time to communicate will be very high
# if the task are too important, some nodes could starve and will have nothing to do.
# 
# As the search is done from the last job n back to the first one, these values should
# be rather close than 100% than 0% in order to to schedule few big tasks rather than 
# a lot of small tasks. 
export MIN_PERCENT_FOR_DISPATCHING=70
export MAX_PERCENT_FOR_DISPATCHING=80
export PERIOD_MPI_TEST_MASTER=10
export PERIOD_MPI_TEST_SLAVE=10

#export CMD_LINE_PARAMS="${CMD_LINE_PARAMS} -periodMPITestMaster ${PERIOD_MPI_TEST_MASTER} -periodMPITestSlave ${PERIOD_MPI_TEST_SLAVE} -minPercentForDispatching ${MIN_PERCENT_FOR_DISPATCHING} -maxPercentForDispatching ${MAX_PERCENT_FOR_DISPATCHING}"

#mpirun --hostfile bhost -np 2 bin/samebatch-muliproduct-binpacking-mpi $1 $2 $3 $4 $5 $6

echo time ${MPIRUN_CMD} -np ${NBR_NODES} ${PROGRAM_NAME} ${CMD_LINE_PARAMS}

time ${MPIRUN_CMD} -np ${NBR_NODES} ${PROGRAM_NAME} ${CMD_LINE_PARAMS}


